package com.wmeimob.fastboot.jiubei.service;

import com.wmeimob.fastboot.jiubei.entity.ShopGoodsComment;
import com.wmeimob.fastboot.jiubei.mapper.ShopGoodsCommentMapper;
import com.wmeimob.fastboot.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @ClassName ShopGoodsCommentServiceImpl
 * @Description  商品评价 服务类实现
 * @Author wjt
 * @Date Sat Aug 29 21:42:58 CST 2020
 * @version 1.0
 **/

@Service
@Transactional(rollbackFor={Exception.class})
@Slf4j
public class ShopGoodsCommentServiceImpl implements ShopGoodsCommentService {

    @Resource
    private ShopGoodsCommentMapper shopGoodsCommentMapper;


    @Override
    public List<ShopGoodsComment> list(ShopGoodsComment shopGoodsComment) {
        Example example = new Example(ShopGoodsComment.class);
        Example.Criteria criteria = example.createCriteria();
	  if(!StringUtils.isEmpty(shopGoodsComment.getId())){
            criteria.andEqualTo("id",shopGoodsComment.getId());
	  }
	  if(!StringUtils.isEmpty(shopGoodsComment.getMemberId())){
            criteria.andEqualTo("memberId",shopGoodsComment.getMemberId());
	  }
	  if(!StringUtils.isEmpty(shopGoodsComment.getNickname())){
            criteria.andLike("nickname",StringUtils.fullFuzzy(shopGoodsComment.getNickname()));
	  }
	  if(!StringUtils.isEmpty(shopGoodsComment.getHeadImg())){
            criteria.andLike("headImg",StringUtils.fullFuzzy(shopGoodsComment.getHeadImg()));
	  }
	  if(!StringUtils.isEmpty(shopGoodsComment.getGoodsId())){
            criteria.andEqualTo("goodsId",shopGoodsComment.getGoodsId());
	  }
	  if(!StringUtils.isEmpty(shopGoodsComment.getGoodsSkuId())){
            criteria.andEqualTo("goodsSkuId",shopGoodsComment.getGoodsSkuId());
	  }
	  if(!StringUtils.isEmpty(shopGoodsComment.getDisplay())){
            criteria.andEqualTo("display",shopGoodsComment.getDisplay());
	  }
	  if(!StringUtils.isEmpty(shopGoodsComment.getContent())){
            criteria.andLike("content",StringUtils.fullFuzzy(shopGoodsComment.getContent()));
	  }
	  if(!StringUtils.isEmpty(shopGoodsComment.getReply())){
            criteria.andLike("reply",StringUtils.fullFuzzy(shopGoodsComment.getReply()));
	  }
	  if(!StringUtils.isEmpty(shopGoodsComment.getScore())){
            criteria.andEqualTo("score",shopGoodsComment.getScore());
	  }
	  if(!StringUtils.isEmpty(shopGoodsComment.getAnonymous())){
            criteria.andEqualTo("anonymous",shopGoodsComment.getAnonymous());
	  }
	  if(!StringUtils.isEmpty(shopGoodsComment.getGmtCreate())){
            criteria.andEqualTo("gmtCreate",shopGoodsComment.getGmtCreate());
	  }
	  if(!StringUtils.isEmpty(shopGoodsComment.getGmtModified())){
            criteria.andEqualTo("gmtModified",shopGoodsComment.getGmtModified());
	  }
        example.orderBy("id").desc();
        List<ShopGoodsComment> shopGoodsComments = shopGoodsCommentMapper.selectByExample(example);
        return shopGoodsComments;
    }

    @Override
    public ShopGoodsComment queryShopGoodsCommentById(Object id) {
        return shopGoodsCommentMapper.selectByPrimaryKey(id);
    }


	@Override
    public void addShopGoodsComment(ShopGoodsComment shopGoodsComment) {
	  shopGoodsComment.setGmtCreate(new Date());
        shopGoodsCommentMapper.insertSelective(shopGoodsComment);
    }

    @Override
    public void removeShopGoodsComment(Long id) {
	  ShopGoodsComment shopGoodsComment = new ShopGoodsComment();
	  shopGoodsComment.setId(id);
        shopGoodsCommentMapper.updateByPrimaryKeySelective(shopGoodsComment);
    }

    @Override
    public void modifyShopGoodsComment(ShopGoodsComment shopGoodsComment) {
		shopGoodsComment.setGmtModified(new Date());
        shopGoodsCommentMapper.updateByPrimaryKeySelective(shopGoodsComment);
    }

}
